Include Nur.DateFormat

/// Creator:      fengliang
/// CreatDate:    2021-03-12
/// Description:  输液巡视表
Class Nur.MNISV3.InfusionTourRec Extends %Persistent
{

/// 巡视日期
Property DHCNurTourDate As %Library.Date(FORMAT = 1) [ InitialExpression = {+$p($h,",",1)}, Required, SqlColumnNumber = 2 ];

/// 巡视时间
Property DHCNurTourTime As %Library.Time [ InitialExpression = {+$p($h,",",2)}, Required, SqlColumnNumber = 3 ];

/// 巡视病人就诊号
Property DHCNurTourAdmDR As %Library.String(TRUNCATE = 1) [ SqlColumnNumber = 4 ];

/// 巡视患者所在病区 
Property DHCNurTourCtlocDR As %Library.String(TRUNCATE = 1) [ SqlColumnNumber = 5 ];

/// 巡视病人床号
Property DHCNurTourPatBed As %Library.String(TRUNCATE = 1) [ SqlColumnNumber = 6 ];

/// 护理医嘱id
Property DHCNurTourCareDR As %Library.String(TRUNCATE = 1) [ SqlColumnNumber = 7 ];

/// 护理医嘱
Property DHCNurTourCareDesc As %Library.String(TRUNCATE = 1) [ SqlColumnNumber = 8 ];

/// 输液医嘱id 
Property DHCNurTourInspectDR As %Library.String(MAXLEN = 200, TRUNCATE = 1) [ SqlColumnNumber = 9 ];

/// 输液医嘱
Property DHCNurTourInspectDesc As %Library.String(MAXLEN = 200, TRUNCATE = 1) [ SqlColumnNumber = 10 ];

/// 输液巡视操作条目 
Property DHCNurTourInspectHandle As %Library.String(DISPLAYLIST = ",Puncture,Tour,Change,Extract", SELECTIVITY = "20%", TRUNCATE = 1, VALUELIST = ",P,T,C,E") [ SqlColumnNumber = 11 ];

/// 输液巡视情况
Property DHCNurTourInspectSTAT As %Library.String(TRUNCATE = 1) [ SqlColumnNumber = 12 ];

/// 输液巡视处理
Property DHCNurTourInspectDeal As %Library.String(TRUNCATE = 1) [ SqlColumnNumber = 13 ];

/// 输液滴速
Property DHCNurTourInspectSP As %Library.String(TRUNCATE = 1) [ SqlColumnNumber = 14 ];

/// 巡视人
Property DHCNurTourUser As %Library.String(TRUNCATE = 1) [ SqlColumnNumber = 15 ];

/// 作废人
Property DHCNurTourCancelUser As %Library.String(TRUNCATE = 1) [ SqlColumnNumber = 16 ];

/// 作废日期
Property DHCNurTourCancelDate As %Library.Date(FORMAT = 1) [ SqlColumnNumber = 17 ];

/// 作废时间
Property DHCNurTourCancelTime As %Library.Time [ SqlColumnNumber = 18 ];

/// 条码类型
Property DHCNurTourBarcodeType As %Library.Time [ SqlColumnNumber = 19 ];

/// 对应 item1~15的类型
Property ItemType As %Library.String(TRUNCATE = 1) [ SqlColumnNumber = 20 ];

Property Item1 As %Library.String(TRUNCATE = 1) [ SqlColumnNumber = 21 ];

Property Item2 As %Library.String(TRUNCATE = 1) [ SqlColumnNumber = 22 ];

Property Item3 As %Library.String(TRUNCATE = 1) [ SqlColumnNumber = 23 ];

Property Item4 As %Library.String(TRUNCATE = 1) [ SqlColumnNumber = 24 ];

Property Item5 As %Library.String(TRUNCATE = 1) [ SqlColumnNumber = 25 ];

Property Item6 As %Library.String(TRUNCATE = 1) [ SqlColumnNumber = 26 ];

Property Item7 As %Library.String(TRUNCATE = 1) [ SqlColumnNumber = 27 ];

Property Item8 As %Library.String(TRUNCATE = 1) [ SqlColumnNumber = 28 ];

Property Item9 As %Library.String(TRUNCATE = 1) [ SqlColumnNumber = 29 ];

Property Item10 As %Library.String(TRUNCATE = 1) [ SqlColumnNumber = 30 ];

Property Item11 As %Library.String(TRUNCATE = 1) [ SqlColumnNumber = 31 ];

Property Item12 As %Library.String(TRUNCATE = 1) [ SqlColumnNumber = 32 ];

Property Item13 As %Library.String(TRUNCATE = 1) [ SqlColumnNumber = 33 ];

Property Item14 As %Library.String(TRUNCATE = 1) [ SqlColumnNumber = 34 ];

Property Item15 As %Library.String(TRUNCATE = 1) [ SqlColumnNumber = 35 ];

Property Item16 As %Library.String(TRUNCATE = 1) [ SqlColumnNumber = 36 ];

Property Item17 As %Library.String(TRUNCATE = 1) [ SqlColumnNumber = 37 ];

Property Item18 As %Library.String(TRUNCATE = 1) [ SqlColumnNumber = 38 ];

Property Item19 As %Library.String(TRUNCATE = 1) [ SqlColumnNumber = 39 ];

Property Item20 As %Library.String(TRUNCATE = 1) [ SqlColumnNumber = 40 ];

Index TourDateAdm On (DHCNurTourDate, DHCNurTourCtlocDR, DHCNurTourAdmDR);

Index TourDate On DHCNurTourDate;

Index TourAdmUser On (DHCNurTourDate, DHCNurTourCtlocDR, DHCNurTourAdmDR, DHCNurTourUser);

Index TourUser On (DHCNurTourDate, DHCNurTourCtlocDR, DHCNurTourUser);

Index TourDateOrd On (DHCNurTourDate, DHCNurTourCtlocDR, DHCNurTourInspectDR);

Index TourOrd On DHCNurTourInspectDR;

Index TourAdmOrd On (DHCNurTourDate, DHCNurTourCtlocDR, DHCNurTourAdmDR, DHCNurTourInspectDR);

/// Creator:      lmm
/// CreatDate:    2019-04-19
/// Description:  输液巡视保存
/// Input：       parr:数据串(key|value^key|value),id:id,userId:用户ID
/// other:        w ##class(Nur.MNISV3.InfusionTourRec).Save()
ClassMethod Save(parr As %String, id As %String, userId As %String, parrJson = "") As %String
{
    s tmp=""
    ;s a=##class(web.DHCMGNurComm).setmoudtmp(parr,.tmp)
    s a=..setmoudtmp(parr,.tmp)
    i (id=""){
        s rec=##class(Nur.MNISV3.InfusionTourRec).%New()
    }else{
        s rec=##class(Nur.MNISV3.InfusionTourRec).%OpenId(id)
    }
    i '$d(tmp("DHCNurTourDate"))  d
    .s tmp("DHCNurTourDate")=+$h
    e  d
    .i tmp("DHCNurTourDate")["-" s tmp("DHCNurTourDate")=$zdh(tmp("DHCNurTourDate"),3)
    .i tmp("DHCNurTourDate")["/" s tmp("DHCNurTourDate")=$zdh(tmp("DHCNurTourDate"),1)  
    i '$d(tmp("DHCNurTourTime"))  d
    .s tmp("DHCNurTourTime")=$p($h,",",2)
    e  d
    .i tmp("DHCNurTourTime")[":" s tmp("DHCNurTourTime")=$zth(tmp("DHCNurTourTime"))
    //取当时患者的等级护理和床号
    i $d(tmp("DHCNurTourAdmDR")) d
    .s tmp("DHCNurTourPatBed")=##class(Nur.MNISV3.Service.PatientInfo).GetBedCode(tmp("DHCNurTourAdmDR"))
    .s tmp("DHCNurTourCareDesc")=##class(Nur.MNISV3.Service.PatientInfo).GetCareLevel(tmp("DHCNurTourAdmDR"))
    .s tmp("DHCNurTourCareDR")=##class(Nur.MNISV3.Service.PatientInfo).GetCareLevel(tmp("DHCNurTourAdmDR"))
    i $d(tmp("DHCNurTourInspectHandle")) d
    .s handleDesc=tmp("DHCNurTourInspectHandle")
    .s tmp("DHCNurTourInspectHandle")=$s(handleDesc="穿刺":"P",handleDesc="巡视":"T",handleDesc="续液":"C",handleDesc="穿刺":"E",1:"T")
    
    i $d(tmp("DHCNurTourDate")) s rec.DHCNurTourDate=tmp("DHCNurTourDate")
    i $d(tmp("DHCNurTourTime")) s rec.DHCNurTourTime=tmp("DHCNurTourTime")
    i $d(tmp("DHCNurTourAdmDR")) s rec.DHCNurTourAdmDR=tmp("DHCNurTourAdmDR")
    i $d(tmp("DHCNurTourCtlocDR")) s rec.DHCNurTourCtlocDR=tmp("DHCNurTourCtlocDR")
    i $d(tmp("DHCNurTourPatBed")) s rec.DHCNurTourPatBed=tmp("DHCNurTourPatBed")    
    i $d(tmp("DHCNurTourCareDR"))&&($g(tmp("DHCNurTourCareDR"))'="") s rec.DHCNurTourCareDR=$replace(tmp("DHCNurTourCareDR"),"-","||")
    i $d(tmp("DHCNurTourCareDesc")) s rec.DHCNurTourCareDesc=tmp("DHCNurTourCareDesc")
    i $d(tmp("DHCNurTourInspectDR"))&&($g(tmp("DHCNurTourInspectDR"))'="") s rec.DHCNurTourInspectDR=$replace(tmp("DHCNurTourInspectDR"),"-","||")
    i $d(tmp("DHCNurTourInspectDesc")) s rec.DHCNurTourInspectDesc=tmp("DHCNurTourInspectDesc")
    i $d(tmp("DHCNurTourInspectHandle")) s rec.DHCNurTourInspectHandle=tmp("DHCNurTourInspectHandle")
    i $d(tmp("DHCNurTourInspectSTAT")) s rec.DHCNurTourInspectSTAT=tmp("DHCNurTourInspectSTAT")
    i $d(tmp("DHCNurTourInspectDeal")) s rec.DHCNurTourInspectDeal=tmp("DHCNurTourInspectDeal")
    i $d(tmp("DHCNurTourInspectSP")) s rec.DHCNurTourInspectSP=tmp("DHCNurTourInspectSP")
    i $d(tmp("DHCNurTourBarcodeType")) s rec.DHCNurTourBarcodeType=tmp("DHCNurTourBarcodeType")
    
    //处理 parrJson 对象
    //"{""5||11"":""jxjxjxjjx"",""5||10"":""hshshh"",""5||2"":""22"",""5||1"":""36.5"",""5||4"":""44"",""5||3"":""33"",""5||6"":""66"",""5||5"":""55"",""5||8"":""有"",""5||7"":""45"",""5||9"":""皮疹^寒战^胸闷""}
    i $g(parrJson)'="" {
        s itemType=""
        s set=##class(Nur.MNISV3.Common.JSON).Decode(parrJson)
        s key=set.Next("")
        while (key'="") {
            s value=set.GetAt(key)
            i key["||" { //分隔字符 第一个是类型
                s itemType=$p(key,"||",1)
                s itemIndex=$p(key,"||",2)
                s itm="Item"_itemIndex  
                if $g(value)'="" s $ZOBJPROPERTY(rec,itm)=value
            }
            s key=set.Next(key)
           
        }
        i itemType'="" s $ZOBJPROPERTY(rec,"ItemType")=itemType
    }
    
    s rec.DHCNurTourUser=userId
    s sc=rec.%Save()
    w $$$ISERR(sc),!
    q:$$$ISERR(sc) "err:"_$SYSTEM.Status.GetErrorText(sc)
    
    //插入工作量
    s ifSpeed=rec.DHCNurTourInspectSP
    s puncturePart=""
    s infusionState=""
    s infusionReason=""
    s infusionMeasure=""
    s locId=rec.DHCNurTourCtlocDR
    s oeoreId=rec.DHCNurTourInspectDR
    s workType=5  //巡视
    s parr="WorkInfusionSpeed|"_ifSpeed_"^WorkPuncturePart|"_puncturePart_"^WorkInfusionState|"_$g(infusionState)
    s parr=parr_"^WorkInfusionReason|"_$g(infusionReason)_"^WorkInfusionMeasure|"_$g(infusionMeasure)
    s scErr=##class(Nur.MNISV3.IPIFWorkLoad).Save(parr,"", userId , locId, oeoreId, workType)
    w rec.%Id(),!
    q rec.%Id()
}

/// Creator:      lmm
/// CreatDate:    2019-04-19
/// Description:  输液巡视删除
/// Input：       parr:数据串(key|value^key|value),id:id
/// other:        w ##class(Nur.MNISV3.InfusionTourRec).Delete()
ClassMethod Delete(id As %String, userId As %String) As %String
{
    q:id="" "err:"_"id为空"
    s rec=##class(Nur.MNISV3.InfusionTourRec).%OpenId(id)
    s rec.DHCNurTourCancelUser=userId
    s rec.DHCNurTourCancelDate=+$h
    s rec.DHCNurTourCancelTime=$p(+$h,",",2)
    s sc=rec.%Save()    
    q:$$$ISERR(sc) "err:"_$SYSTEM.Status.GetErrorText(sc)
    q 0
}

ClassMethod setmoudtmp(parr, tmval)
{
    s l=$L(parr,"^")
    for i=1:1:l
    {
        s itm=$P(parr,"^",i)
        if itm="" continue
        s name=$P(itm,"|")
        s val=$P(itm,"|",2,*)
        s tmval(name)=val
    }
    q 0
}

Storage Default
{
<Data name="InfusionTourRecDefaultData">
<Value name="1">
<Value>%%CLASSNAME</Value>
</Value>
<Value name="2">
<Value>DHCNurTourDate</Value>
</Value>
<Value name="3">
<Value>DHCNurTourTime</Value>
</Value>
<Value name="4">
<Value>DHCNurTourAdmDR</Value>
</Value>
<Value name="5">
<Value>DHCNurTourCtlocDR</Value>
</Value>
<Value name="6">
<Value>DHCNurTourPatBed</Value>
</Value>
<Value name="7">
<Value>DHCNurTourCareDR</Value>
</Value>
<Value name="8">
<Value>DHCNurTourCareDesc</Value>
</Value>
<Value name="9">
<Value>DHCNurTourInspectDR</Value>
</Value>
<Value name="10">
<Value>DHCNurTourInspectDesc</Value>
</Value>
<Value name="11">
<Value>DHCNurTourInspectHandle</Value>
</Value>
<Value name="12">
<Value>DHCNurTourInspectSTAT</Value>
</Value>
<Value name="13">
<Value>DHCNurTourInspectDeal</Value>
</Value>
<Value name="14">
<Value>DHCNurTourInspectSP</Value>
</Value>
<Value name="15">
<Value>DHCNurTourUser</Value>
</Value>
<Value name="16">
<Value>DHCNurTourCancelUser</Value>
</Value>
<Value name="17">
<Value>DHCNurTourCancelDate</Value>
</Value>
<Value name="18">
<Value>DHCNurTourCancelTime</Value>
</Value>
<Value name="19">
<Value>DHCNurTourBarcodeType</Value>
</Value>
<Value name="20">
<Value>ItemType</Value>
</Value>
<Value name="21">
<Value>Item1</Value>
</Value>
<Value name="22">
<Value>Item2</Value>
</Value>
<Value name="23">
<Value>Item3</Value>
</Value>
<Value name="24">
<Value>Item4</Value>
</Value>
<Value name="25">
<Value>Item5</Value>
</Value>
<Value name="26">
<Value>Item6</Value>
</Value>
<Value name="27">
<Value>Item7</Value>
</Value>
<Value name="28">
<Value>Item8</Value>
</Value>
<Value name="29">
<Value>Item9</Value>
</Value>
<Value name="30">
<Value>Item10</Value>
</Value>
<Value name="31">
<Value>Item11</Value>
</Value>
<Value name="32">
<Value>Item12</Value>
</Value>
<Value name="33">
<Value>Item13</Value>
</Value>
<Value name="34">
<Value>Item14</Value>
</Value>
<Value name="35">
<Value>Item15</Value>
</Value>
<Value name="36">
<Value>Item16</Value>
</Value>
<Value name="37">
<Value>Item17</Value>
</Value>
<Value name="38">
<Value>Item18</Value>
</Value>
<Value name="39">
<Value>Item19</Value>
</Value>
<Value name="40">
<Value>Item20</Value>
</Value>
</Data>
<DataLocation>^Nur.MNISV3.InfusionTourRecD</DataLocation>
<DefaultData>InfusionTourRecDefaultData</DefaultData>
<IdLocation>^Nur.MNISV3.InfusionTourRecD</IdLocation>
<IndexLocation>^Nur.MNISV3.InfusionTourRecI</IndexLocation>
<StreamLocation>^Nur.MNISV3.InfusionTourRecS</StreamLocation>
<Type>%Storage.Persistent</Type>
}

}
